<?php
session_save_path('../../sessions');
session_start();

// If we didn't come from the findNewRegistrations.php, send back to login routing page
if( !isset($_SESSION['activation']) || (isset($_SESSION['activation']) && $_SESSION['activation'] != 1) ) {
    
    // Make sure the same activation can't be performed again until you go back to the activation page
    unset($_SESSION['activation']);
    
    header("location:../../login_success.php");
}
else {
    
    
    // If the activationID SHA doesn't match the SHA created from the form, then something
    // suspicious is happening and we go back to the routing page
    if( strcmp($_POST['activationID'], sha1($_POST['username'].$_POST['id'])) != 0 )
    {
        // Make sure the same activation can't be performed again until you go back to the activation page
        unset($_SESSION['activation']);
        header("location:../../login_success.php");
    }

    // Connect to our database
    include("../dbconnection.php");
    
    // Select all users that have a last connected time of 0 (UNIX epoch)
    // 0 is used since it would never be set as such in the user creation script    
    $db_query = "UPDATE $TABLE_USERS SET $TABLE_USERS_LASTCONNECTED=".date("U")." WHERE $TABLE_USERS_USERID=".$_POST['id'];

    // Execute the query
    mysql_query($db_query);
    
    // Close the connection
    mysql_close();
    
    // Make sure the same activation can't be performed again until you go back to the activation page
    unset($_SESSION['activation']);

    // Go back to where we were
    header("location:../../admin_monitorRegistrations.php");
    
}